package com.quktzhuanka.app.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.quktzhuanka.app.R;
import com.quktzhuanka.app.activity.SearchResultActivity;
import com.quktzhuanka.app.bean.TaobaoGuestBean;
import com.quktzhuanka.app.common.SPUtils;
import com.quktzhuanka.app.my.CollectionActivity;
import com.quktzhuanka.app.utils.StringUtils;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

/**
 * 开发者：田哥哥
 * 时间:2018/7/26 15:54
 * 说明：
 */
public class ShopRecyclerAdapter2 extends CommonAdapter<TaobaoGuestBean.TaobaoGuesChildtBean> {
    Drawable drawable;
    private OnDeleteClickLister mDeleteClickListener;

    public ShopRecyclerAdapter2(Context context, int layoutId, List<TaobaoGuestBean.TaobaoGuesChildtBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, TaobaoGuestBean.TaobaoGuesChildtBean item, int position) {
        //设置图片
        ImageView imageView = holder.getView(R.id.image);
        Glide.with(mContext).load(item.getPict_url()).placeholder(R.drawable.no_banner).dontAnimate().into(imageView);

        ((TextView) holder.getView(R.id.title_child)).setText(item.getTitle());
        //券后
        holder.setText(R.id.tx2, "￥" + String.format("%.2f", (StringUtils.doStringToDouble(item.getZk_final_price()) - StringUtils.doStringToDouble(item.getCoupon_amount()))));
        //券后2
        TextView tx2_2 = holder.getView(R.id.tx2_2);
        //设置删除线
        tx2_2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tx2_2.setText(item.getZk_final_price());
        //内部
        TextView tx3 = holder.getView(R.id.tx3);
        TextView tx2 = holder.getView(R.id.tx2);
        tx3.setText(item.getCoupon_amount()==null?"0":item.getCoupon_amount().replace(".00", ""));
        try {
            if(mContext instanceof SearchResultActivity){
                holder.setText(R.id.tx4, "预估赚" + String.format("%.2f",  Double.valueOf(item.getCommission_rate())*SPUtils.getIntData(mContext,"rate",0)/1000000*Double.valueOf(tx2.getText().toString().replace("￥",""))));

            }else{
                holder.setText(R.id.tx4, "预估赚" + item.getCommission());
            }
        } catch (Exception e) {
            holder.setText(R.id.tx4, "预估赚0");
        }
        if(mContext instanceof CollectionActivity){
            holder.getView(R.id.tv_delete).setTag(position);
            holder.getView(R.id.tv_delete).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mDeleteClickListener != null) {
                        mDeleteClickListener.onDeleteClick(v, (Integer) v.getTag());
                    }
                }
            });
        }
    }

    public void setOnDeleteClickListener(OnDeleteClickLister listener) {
        this.mDeleteClickListener = listener;
    }

    public interface OnDeleteClickLister {
        void onDeleteClick(View view, int position);
    }
}
